import {defineStore} from "pinia";

export const useUserStore = defineStore('user', {
    persist: true, //使用持久化插件
    state: () => {   //是一个函数，返回一个对象，用于存储状态
        return {
            userInfo: {} as IUser,
            token: '',
            refreshToken: '',
        }
    },
    getters: {},  //用于存储计算属性
    actions: {  //用于封装业务逻辑
        logout() {
            this.userInfo = {} as IUser
            this.token = ''
            this.refreshToken = ''
        },
        loginSuccess(userInfo: any, token: any, refreshToken: any) {
            this.userInfo = userInfo
            this.token = token
            this.refreshToken = refreshToken
        },
    },
})